package Homework;

import java.util.Scanner;

public class Work {
    public static void main(String[] args) {
        work1 work1 = new work1();
        work2 work2 = new work2(work1);
        work1.start();
        work2.start();

    }
}
class work1 extends Thread{
    private boolean loop=true;

    @Override
    public void run() {
        while (loop) {
            System.out.println((int) (Math.random() * 100 + 1));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}
class work2 extends Thread{
    private work1 work;
    public work2(work1 work) {
        this.work = work;
    }
    Scanner scanner=new Scanner(System.in);
    @Override
    public void run() {
       while (true){
           char s=scanner.next().toUpperCase().charAt(0);
           if (s=='Q'){
              work.setLoop(false);
              break;
           }
       }
    }
}